#!/bin/bash

readonly GUILD_SERVICE_ROOT=$(pwd)/../..
readonly SERVICE_BOX_ROOT=$GUILD_SERVICE_ROOT/../../../..
readonly PROJECT_NAME=GuildService

declare -r GUILD_SERVICE_LIST=(GuildServiceBasic GuildServiceQuery GuildServiceAuth GuildServiceWelfare)

echo -e "\033[32m "-- guild_service_root:" $GUILD_SERVICE_ROOT \033[0m"
echo -e "\033[32m "-- service_box_root:" $SERVICE_BOX_ROOT \033[0m"

mkdir -p $GUILD_SERVICE_ROOT/package
cd $GUILD_SERVICE_ROOT/package

mkdir -p include/$PROJECT_NAME/struct
find $SERVICE_BOX_ROOT/src/repo/src/include/guild* -name *Arg_struct.h | xargs -I {} cp -r {} include/$PROJECT_NAME/struct
find $SERVICE_BOX_ROOT/src/repo/src/include/guild* -name *Res_struct.h | xargs -I {} cp -r {} include/$PROJECT_NAME/struct

mkdir -p include/$PROJECT_NAME/proxy
find $SERVICE_BOX_ROOT/src/repo/src/include/guild*/*/proxy -name *proxy.h | xargs -I {} cp -r {} include/$PROJECT_NAME/proxy

mkdir -p protobuf/$PROJECT_NAME
find $SERVICE_BOX_ROOT/src/repo/lib/guild* -name *.a | xargs -I {} cp -r {} protobuf/$PROJECT_NAME

mkdir -p proxy/$PROJECT_NAME
find $SERVICE_BOX_ROOT/src/repo/lib/proxy -name *.a | grep Guild | xargs -I {} cp -r {} proxy/$PROJECT_NAME

mkdir -p stub/$PROJECT_NAME
find $SERVICE_BOX_ROOT/src/repo/lib/stub -name *.a | grep Guild | xargs -I {} cp -r {} stub/$PROJECT_NAME

mkdir -p lib/$PROJECT_NAME
find $SERVICE_BOX_ROOT/src/repo/lib/stub -name *.so | grep Guild | xargs -I {} cp -r {} lib/$PROJECT_NAME

mkdir -p doc/$PROJECT_NAME
cp -r ../doc/* doc/$PROJECT_NAME

echo "packing..."
# tar -zcvf protobuf.tar.gz protobuf/
# tar -zcvf proxy.tar.gz proxy/
# tar -zcvf stub.tar.gz stub/
# tar -zcvf lib.tar.gz lib/

tar -zcvf guild-service-cpp-linux-sdk-0.1.0.tar.gz \
package.json include/ protobuf proxy stub lib doc

rm -rf include protobuf proxy stub lib doc

echo $(pwd)

echo "pack success"

# for service in ${GUILD_SERVICE_LIST[*]} 
# do
#   echo $service
# done

#mkdir -p $GUILD_SERVICE_ROOT/package